package com.example.spring.bean.load09inject;

import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.core.env.ConfigurableEnvironment;

import java.util.Map;

/**
 * 测试
 * <p>
 * <p>
 */
public class AnnoValueTest {
    public static void main(String[] args) {
        AnnotationConfigApplicationContext app = new AnnotationConfigApplicationContext(InitConfig.class);
        Object mail = app.getBean("mail");
        //Mail{name='zyy', host='xx.xx.x.x', tt='hello'}
        System.out.println(mail);

        //从环境变量中直接获取
        ConfigurableEnvironment env = app.getEnvironment();
        System.out.println("通过env获取host === " + env.getProperty("mail.host"));

        Map<String, Mail> beansOfType = app.getBeansOfType(Mail.class);
        //{
        // mail=Mail{name='zyy', host='xx.xx.x.x', tt='hello', from='null'},
        // mail2=Mail{name='zyy', host='xx.xx.x.x', tt='hello', from='dssd'}
        // }
        System.out.println("beansOfType == " + beansOfType);

        System.out.println("------ Autowired -------");
        MailDao mailDao = app.getBean("mailDao",MailDao.class);
        mailDao.print();

        app.close();
    }
}
